<?php
namespace Admin\Controller;
use Think\Page;
class NewsController extends BaseController{
    function index(){
     /*  $count=M('news')->count();//获取总记录数
      $mypage=new Page($count,2);//实例化分页类
      
      $p=I('get.p',1);//获取当前页码
     /*  $start=($p-1)*5;//计算起始的limit的位置
      $rows=M('news')->limit($start,5)->select(); */
      
     /* $rows=M('news')->page($p,2)->select();
      $show=$mypage->show();
     
      //echo $show;
      $this->assign(array('rows'=>$rows,'show'=>$show)); */
      if(IS_AJAX){
          
          $page=I('post.page',1);//从$_POST['page']获取当前页码
          $total=I('post.rows',10);//从$_POST['rows']获取每页行数
          $data=M('news')->page($page,$total)->select();//获取分页数据
          $count=M('news')->count();//获取总记录数
          
          $data=array(
              'total'=>$count,//总的记录数
              'rows'=>$data,//当前页的数据
          );
          $this->ajaxReturn($data);//返回json数据
          die;
      }
        
      $this->display();
        
    }
    
    function add(){
        
        
    }
    
    function edit(){
       
    
    }
    /* function  find(){
        $this->redirect('index');
        //find 一维数组
        //select 二维数组
        //getField 返回第一条查找的字段的值 是一个字符串
        //$result=M('news')->where("id='5'")->select();
        $result=M('news')->getField('title,type');
        print_r($result);
        echo M('news')->getLastSql();
    
    
    
    } */
   
    function  _empty(){
        echo '404';
    }
    }
      /*  $data[]=array(
           'title'=>'小米8月底发布',
           'content'=>'小米将在深圳举办年度旗舰发布会',
           'time'=>time(),
           'type'=>1
           
       );
       $data[]=array(
           'title'=>'一加6今天售卖',
           'content'=>'今天一加6手机全网销售额达10亿',
           'time'=>time(),
           'type'=>2
           
        ); */
       
       //M('news')->add(I('post.'));
      // $result=M('news')->addAll($data);
       //$result=M('news')->where("id='7'")->save(array('title'=>'科技新闻','type'=>2));
      // $result=M('news')->where("id='6'")->delete();
       //$result= M('news')->where(array('title'=>array('like','%贸易%')))->select();
      // $result= M('news')->where(array('id'=>array('between',array(5,15))))->select();
       //$result= M('news')->field('title,content')->order('title desc,id asc')->limit(2,5)->select();
    /*    $result=false;
       if($result!==false){
           
           echo'执行成功了';
       }else{
           echo'执行失败';
       }
       
       echo $result;
       echo '<br>';
       echo M('news')->getLastSql();
    }
     */
    
 
